package  {
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	import flash.text.Font;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.getDefinitionByName;
	
	/**
	* 嵌入外部字体
	* @author PhoenixKerry（http://blog.sina.com.cn/yyy98）
	*/
	public class Main extends Sprite {
		private var textField:TextField;
		private var fontLoader:Loader;
		
		public function Main() {
			textField = new TextField();
			textField.selectable = false;
			textField.textColor = 0xFF0000;
			textField.autoSize = TextFieldAutoSize.LEFT;
			addChild(textField);
			
			fontLoader = new Loader();
			fontLoader.load(new URLRequest("./assets/game_font.swf"), new LoaderContext(false, loaderInfo.applicationDomain));
			fontLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadFontCompleteHandler);
		}
		
		// 读取字体完成，通过 TextFormat 应用到 TextField 中的文字
		private function loadFontCompleteHandler(e:Event):void {
			fontLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadFontCompleteHandler);
			var alphaFitnessFontClazz:Class = getDefinitionByName("AlphaFitnessFont") as Class;
			
			Font.registerFont(alphaFitnessFontClazz);
			var alphaFitnessFont:Font = new alphaFitnessFontClazz() as Font;
			
			var textFormat:TextFormat = new TextFormat(alphaFitnessFont.fontName, 60, null, true);
			textField.defaultTextFormat = textFormat;
			textField.embedFonts = true;
			textField.text = "Hello, Zynga!!!";
		}
		
	}
}